#阶段1 - 打包
FROM 192.1.37.31/public/node:16.16.0-alpine 
ADD fssc-invoice-web.tar.gz /opt/sources
WORKDIR /opt/sources
RUN mkdir -p /node/work/build
RUN echo -e "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/main\n\ https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/community" > /etc/apk/repositories \
    && apk update \
    && apk add git
RUN rm -rf fssc-common &&  git clone -b master2 http://192.1.37.153:3000/fssc-front-group/fssc-common.git
RUN npm config set registry=https://registry.npmmirror.com/ 
RUN if ! type pnpm ; then npm install pnpm@8 -g ; fi 
RUN pnpm config set registry=https://registry.npmmirror.com/ && pnpm -v
RUN pnpm install && pnpm run build:test 
RUN mv dist /node/work/build/ \
  && pnpm run build:prod \
  && mv dist /node/work/build/online
#---分割线---
RUN cp -rp /opt/sources/nginx /node/work/build
WORKDIR /node
RUN tar zcf fssc-invoice-web.tar.gz /node/work
# 阶段2 - 运行时 test#
# Dockerfile 基于阶段 1 的应用程序包生成镜像
# 该镜像将在正式环境中运行
# 基础镜像
FROM base/openresty:1.17.8.1
LABEL maintainer="mingzi.xing <mingzi.xing@sjgo365.com>"
# 新建目录
RUN mkdir -p /home/finance/App/foobar.cbestcd.lo/
WORKDIR /home/finance/App/foobar.cbestcd.lo/
# 导入打包好的文件
COPY --from=0 /node/fssc-invoice-web.tar.gz /home/finance/App/foobar.cbestcd.lo/
# 使 nginx 日志输出在标准输出
RUN tar zxvf fssc-invoice-web.tar.gz \
    && echo "=================" \
    && mv node/work/* ./ \
    && ls -a /home/finance/App/foobar.cbestcd.lo/ \
    && ln -snf /dev/stdout /home/finance/App/foobar.cbestcd.lo/build/nginx/logs/access.log \
    && ln -snf /dev/stderr /home/finance/App/foobar.cbestcd.lo/build/nginx/logs/error.log
# 启动命令
CMD ["/opt/openresty/nginx/sbin/nginx", "-p", "build/nginx", "-g", "daemon off;"]